﻿using System;
using KuiHuaBaoDian.Services.Lockstep;
using Runtime.Services.Battle.Entity;
using Runtime.Services.BattleAttack;

namespace Runtime.Services.Battle.Behaviour {

    /// <summary>
    /// 攻击命中行为
    /// </summary>
    public interface IDFR_BattleBehaviour_Hit : IDFR_BattleBehaviour {

        /// <summary>
        /// 实体
        /// </summary>
        new public interface IEntity : IDFR_BattleBehaviour.IEntity {

            /// <summary>
            /// 攻击时的快照
            /// </summary>
            IDFR_BattleAttackSnapshot AttackSnapshot { get; }

            /// <summary>
            /// 目标实体ID
            /// </summary>
            DFR_BattleEntityInstanceID TargetEntityInstanceID { get; }

            /// <summary>
            /// 目标地图位置提供者
            /// </summary>
            IDFR_BattleMapPositionProvider TargetMapPositionProvider { get; }
        }
    }

    [Implement(typeof(IDFR_BattleBehaviour_Hit))]
    internal sealed class DFR_BattleBehaviour_Hit : DFR_BattleBehaviour, IDFR_BattleBehaviour_Hit {

        new private IDFR_BattleBehaviour_Hit.IEntity Entity => (IDFR_BattleBehaviour_Hit.IEntity)base.Entity;

        protected override void Initialize() {
        }

        protected override IDFR_BattleBehaviourInfo LogicFrame() {
            LockstepTimerService.Instance.Start((F64)BattleServiceBase.BATTLE_BULLET_HIT_TIME, 1, onComplete: data => {
                BattleAttackService.Instance.Hit(Entity.AttackSnapshot, Entity.TargetEntityInstanceID, Entity.TargetMapPositionProvider,
                    sourceModelDictionary: DFR_BattleBase.DataCenter.Models.AttackSourceDictionary,
                    targetModelDictionary: DFR_BattleBase.DataCenter.Models.AttackTargetDictionary);
            });

            return new DFR_BattleBehaviourInfo {
                Type = DFR_BattleBehaviourType.Hit,
            };
        }

        protected override void Execute(IDFR_BattleBehaviourInfo info) {
        }

        protected override void Update(IDFR_BattleBehaviourInfo info, float interpolation) {
            StateMachine.State = DFR_BattleEntityState.Attack;
        }
    }
}
